package com.sailing.xjpb.orm.intercepter;

import com.sailing.xjpb.common.orm.SailingRepositoryContext;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * repository上下文实现
 *
 * @author sutao
 */
@Slf4j
public final class SailingCrudRepositoryContext implements SailingRepositoryContext {

    /**
     * 存放租户标识
     */
    private static final ThreadLocal<Boolean> TENANT_CODE_FLAG = new ThreadLocal<>();


    @Override
    public boolean getTenantCodeFlag() {
        return SailingCrudRepositoryContext.getSqlTenantCodeFlag();
    }

    public static void clean() {
        TENANT_CODE_FLAG.remove();
    }

    public static boolean getSqlTenantCodeFlag() {
        Boolean flag = TENANT_CODE_FLAG.get();
        return Objects.isNull(flag) ? Boolean.FALSE : flag;
    }

    public static void setSqlTenantCodeFlag(boolean tenantCodeFlag) {
        TENANT_CODE_FLAG.set(tenantCodeFlag);
    }
}
